import Vue from 'vue'
import VueRouter from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'

Vue.use(VueRouter)

const router = new VueRouter({
    // 是否使用 HTML5 history 模式
    mode: 'history',
    // 是否使用虚拟模式
    abstract: true,
    // 定义路由根路径
    root: '/',
    routes: [{
            path: '/login',
            name: 'login',
            component: r => require.ensure([], () => r(require('page/login')), 'login'),
        },

        {
            path: '/',
            name: 'content',
            component: resolve => require(['page/base/Layout/App.vue'], resolve),
            children: [
              {
                path: '/home',
                name: '首页',
                meta: {
                  title: '首页',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/home')), 'home'),
              },
              {
                path: 'platform-info',
                name: 'platformInfo',
                meta: {
                  title: '平台信息',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/platformInfo')), 'platformInfo')
              },

              {
                    path: 'channel-info',
                    name: 'channelInfo',
                    meta: {
                      title: '渠道信息',
                      keepAlive: false,
                      requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/channelInfo')), 'channelInfo')
                },
              {
                path: 'brand',
                name: 'brand',
                meta: {
                  title: '品牌信息',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/brand')), 'brand'),
              },
              {
                path: 'brand-add',
                name: 'brandAdd',
                meta: {
                  title: '品牌信息添加',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/brand/add')), 'brandAdd'),
              },
              {
                path: 'brand-add-edit',
                name: 'brandAddEdit',
                meta: {
                  title: '品牌信息编辑',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/brand/edit')), 'brandEdit'),
              },
                {
                    path: 'commodity-info',
                    name: 'commodityInfo',
                    meta: {
                        title: '商品信息',
                        keepAlive: false,
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/commodityInfo')), 'commodityInfo'),
                },
              {
                path: 'commodity-info-add',
                name: 'commodityInfoAdd',
                meta: {
                  title: '商品信息添加',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/commodityInfo/add')), 'commodityInfoAdd'),
              },
              {
                path: 'cooperation-company-info',
                name: 'cooperationCompanyInfo',
                meta: {
                  title: '合作公司',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/cooperationCompanyInfo')), 'cooperationCompanyInfo')
              },

                {
                    path: 'supplier-info',
                    name: 'supplier-info',
                    meta: {
                        title: '供应商信息',
                        keepAlive: false,
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/supplierInfo')), 'supplierInfo')
                },
              {
                path: 'supplier-info-add',
                name: 'supplierInfoAdd',
                meta: {
                  title: '合作公司添加',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/supplierInfo/add')), 'supplierInfoAdd')
              },
              {
                path: 'supplier-info-edit',
                name: 'supplyInfoEdit',
                meta: {
                  title: '合作公司编辑',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/supplierInfo/edit')), 'supplierInfoEdit')
              },
                {
                    path: 'channel-shop',
                    name: 'channelShop',
                    meta: {
                        title: '渠道商品详情',
                        keepAlive: false,
                        requireAuth: true,
                    },
                    component: r => require.ensure([], () => r(require('page/base/channelShop')), 'channelShop')
                },
                {
                    path: 'brand-info',
                    name: 'brandInfo',
                    meta: {
                        title: '品牌信息',
                        keepAlive: false,
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/brandInfo')), 'brandInfo')
                },
              {
                path: 'item-category',
                name: '商品品类',
                meta: {
                  title: '商品品类',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/itemCategory')), 'itemCategory')
              },
                {
                    path: 'cooperation',
                    name: 'cooperation',
                    meta: {
                        title: '授权产品详情',
                        keepAlive: false,
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/cooperation')), 'cooperation')
                },
                {
                    path: 'cooperation-add',
                    name: 'cooperation-add',
                    meta: {
                        requireAuth: true,
                        keepAlive: false,
                        title: '授权产品详情添加',
                    },
                    component: r => require.ensure([], () => r(require('page/base/cooperation/add')), 'cooperationAdd')
                },
                {
                    path: 'warehouse-info',
                    name: 'warehouse-info',
                    meta: {
                        title: '仓库信息',
                        keepAlive: false,
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/warehouseInfo')), 'warehouseInfo')
                },
                {
                    path: 'stock',
                    name: 'stock',
                    meta: {
                        title: '库存统计',
                        keepAlive: false,
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/stock')), 'stock')
                },

                {
                    path: 'company-info',
                    name: 'company-info',
                    meta: {
                        title: '公司信息',
                        keepAlive: false,
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/companyInfo')), 'companyInfo')
                },
              {
                path: 'new-company-info',
                name: 'new-company-info',
                meta: {
                  title: '新公司信息',
                  keepAlive: false,
                  requireAuth: true
                },
                component: r => require.ensure([], () => r(require('page/base/newCompanyInfo')), 'newCompanyInfo')
              },

                {
                    path: 'bill-order',
                    name: 'bill-order',
                    meta: {
                        title: '采购发票',
                        keepAlive: false,
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/billOrder')), 'billOrder')
                },
                {
                    path: 'purchase-notice-view',
                    name: 'purchaseNoticeView',
                    meta: {
                        requireAuth: true,
                        keepAlive: false,
                        title: '采购发票查看',
                    },
                    component: r => require.ensure([], () => r(require('page/base/myReview/view')), 'purchaseNoticeView')
                },
                {
                    path: 'bill-order-invoice-view',
                    name: 'billOrderInvoiceView',
                    meta: {
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/billOrder/invoiceView')), 'billOrderInvoiceView')
                },
                {
                    path: 'bill-order-pay-view',
                    name: 'billOrderPayView',
                    meta: {
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/billOrder/payView')), 'billOrderPayView')
                },
                {
                    path: 'bill-order-invoice-detail',
                    name: 'billOrderInvoiceDetail',
                    meta: {
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/billOrder/invoiceDetail')), 'billOrderInvoiceDetail')
                },

                {
                    path: 'my-review',
                    name: 'myReview',
                    meta: {
                        requireAuth: true,
                        title: '采购申请',
                        keepAlive: false,
                    },
                    component: r => require.ensure([], () => r(require('page/base/myReview')), 'myReview')
                },
              {
                path: 'my-review-detail',
                name: 'myReviewDetail',
                meta: {
                  requireAuth: true,
                  title: '采购单查看',
                  keepAlive: false,
                },
                component: r => require.ensure([], () => r(require('page/base/myReview/detail')), 'myReviewDetail')
              },
                {
                    path: 'order-info',
                    name: 'order-info',
                    meta: {
                        requireAuth: true,
                        title: '采购单添加',
                        keepAlive: false,
                    },
                    component: r => require.ensure([], () => r(require('page/base/orderInfo')), 'orderInfo')
                },
                {
                    path: 'activity-plan',
                    name: 'activityPlan',
                    meta: {
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/activityPlan')), 'activityPlan')
                },
                {
                    path: 'complaint',
                    name: 'complaint',
                    meta: {
                        keepAlive:false,
                        title: '诉单管理',
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/complaint')), 'complaint')
                },
                {
                    path: 'complaint-add',
                    name: 'complaintAdd',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '诉单添加',
                    },
                    component: r => require.ensure([], () => r(require('page/base/complaint/add')), 'complaintAdd')
                },
                {
                    path: 'complaint-modify',
                    name: 'complaintModify',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '诉单修改',
                    },
                    component: r => require.ensure([], () => r(require('page/base/complaint/modify')), 'complaintModify')
                },
                {
                    path: 'complaint-returnGoods',
                    name: 'complaintReturnGoods',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '诉单退货',

                    },
                    component: r => require.ensure([], () => r(require('page/base/complaint/returnGoods')), 'complaintReturnGoods')
                },
                {
                    path: 'complaint-reissue',
                    name: 'complaintReissue',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '换货补发',
                    },
                    component: r => require.ensure([], () => r(require('page/base/complaint/reissue')), 'complaintReissue')
                },
                {
                    path: 'complaint-exchangeGoods',
                    name: 'complaintExchangeGoods',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '换货申请',
                    },
                    component: r => require.ensure([], () => r(require('page/base/complaint/exchangeGoods')), 'complaintExchangeGoods')
                },
                {
                    path: 'complaint-exchangeConfirm',
                    name: 'complaintExchangeConfirm',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '换货确认',
                    },
                    component: r => require.ensure([], () => r(require('page/base/complaint/exchangeConfirm')), 'complaintExchangeConfirm')
                },
                {
                    path: 'external-complain',
                    name: 'external-complain',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '外部订单',
                    },
                    component: r => require.ensure([], () => r(require('page/base/externalComplain')), 'externalComplain')
                },
                {
                    path: 'external-complain-add',
                    name: 'externalComplainAdd',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '外部订单添加',

                    },
                    component: r => require.ensure([], () => r(require('page/base/externalComplain/add')), 'externalComplainAdd')
                },
                {
                    path: 'external-complain-edit',
                    name: 'externalComplainEdit',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '外部订单编辑',
                    },
                    component: r => require.ensure([], () => r(require('page/base/externalComplain/edit')), 'externalComplainEdit')
                },
                {
                    path: 'order-query',
                    name: 'orderQuery',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '订单查询',
                    },
                    component: r => require.ensure([], () => r(require('page/base/orderQuery')), 'orderQuery')
                },
                {
                    path: 'order-query-detail',
                    name: 'orderQueryDetail',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '订单查询详情',

                    },
                    component: r => require.ensure([], () => r(require('page/base/orderQuery/detail')), 'orderQueryDetail')
                },
                {
                    path: 'platform-order',
                    name: 'platformOrder',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '非平台订单',
                    },
                    component: r => require.ensure([], () => r(require('page/base/platformOrder')), 'platformOrder')
                },
                {
                    path: 'platform-order-add',
                    name: 'platformOrderAdd',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '非平台订单添加',

                    },
                    component: r => require.ensure([], () => r(require('page/base/platformOrder/add')), 'platformOrderAdd')
                },
                {
                    path: 'platform-order-look',
                    name: 'platformOrderLook',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '非平台订单查看',

                    },
                    component: r => require.ensure([], () => r(require('page/base/platformOrder/look')), 'platformOrderLook')
                },
                {
                    path: 'user-manage',
                    name: 'userManage',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '员工管理',
                    },
                    component: r => require.ensure([], () => r(require('page/base/userManage')), 'userManage')
                },
                {
                    path: 'power-manage',
                    name: 'powerManage',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '角色管理',
                    },
                    component: r => require.ensure([], () => r(require('page/base/powerManage')), 'powerManage')
                },
                {
                    path: 'order-daily',
                    name: 'orderDaily',
                    meta: {
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/orderDaily')), 'orderDaily')
                },
                {
                    path: 'brand-daily',
                    name: 'brandDaily',
                    meta: {
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/brandDaily')), 'brandDaily')
                },
                {
                    path: 'channel-daily',
                    name: 'channelDaily',
                    meta: {
                        requireAuth: true
                    },
                    component: r => require.ensure([], () => r(require('page/base/channelDaily')), 'channelDaily')
                },

                {
                    path: 'purchase-plan',
                    name: 'purchasePlan',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '采购计划',
                    },
                    component: r => require.ensure([], () => r(require('page/base/purchasePlan')), 'purchasePlan')
                },
                {
                    path: 'purchase-plan-edit',
                    name: 'purchasePlanEdit',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '采购计划编辑',

                    },
                    component: r => require.ensure([], () => r(require('page/base/purchasePlan/edit')), 'edit')
                },
                {
                    path: 'pur-remit',
                    name: 'purRemit',
                    meta: {
                        requireAuth: true,
                        keepAlive:false,
                        title: '财务打款',
                    },
                    component: r => require.ensure([], () => r(require('page/base/purRemit')), 'purRemit')
                },
                {
                path: 'daily-expense',
                name: 'dailyExpense',
                meta: {
                  requireAuth: true,
                  keepAlive:false,
                  title: '日常支出',
                },
                component: r => require.ensure([], () => r(require('page/base/dailyExpense')), 'dailyExpense')
              },
              //统计分析
              {
                path: 'analysis',
                name: 'analysis',
                meta: {
                  requireAuth: true,
                  keepAlive:false,
                  title: '统计分析',
                },
                component: r => require.ensure([], () => r(require('page/base/analysis')), 'dailyExpense')
              },

            ],
            redirect: '/login'
        },
    ]
});


/***
 * 全局钩子函数
 ***/

router.beforeEach((to, from, next) => {
    if (to.meta.requireAuth) {
        if (localStorage.getItem('accessToken')) {
            next();
        } else {
            next({
                path: '/',
            });
        }
    } else {
        next();
    }
});

export default router
